import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import Layout from '../layout/index.vue'
import NotFound from '../views/error/404.vue'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the views roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    cache: false                if set true, the views will  be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    hidden: true                 if set true, item will not show in the sidebar(default is false)
    alwaysShow: true             if set true, will always show the root menu
*                                if not set alwaysShow, when item has more than one children route,
*                                it will becomes nested mode, otherwise not show the root menu
  }
 */
export const constantRoutes: RouteRecordRaw[] = [
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/login/index.vue'),
    meta: { hidden: true },
  },
  {
    path: '/401',
    name: '401',
    component: () => import(/* webpackChunkName: "403" */'../views/error/401.vue'),
    meta: {
      hidden: true,
    },
  },
  {
    path: '/404',
    name: '404',
    meta: {
      hidden: true,
    },
    component: () => import(/* webpackChunkName: "404" */'../views/error/404.vue'),
  },

  {
    path: '/redirect',
    component: Layout,
    meta: {
      hidden: true,
    },
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index.vue'),
      },
    ],
  },
  { path: '/:pathMatch(.*)*', component: NotFound, meta: { hidden: true } },
  {
    path: '/',
    component: Layout,
    meta: {
      icon: 'chart',
      title: '首页管理',
    },
    redirect: '/home',
    children: [
      {
        path: 'home',
        name: 'Home',
        component: () => import('../views/home/index.vue'),
        meta: {
          title: '首页',
          icon: 'list',
        },
      }],
  },
]

export const asyncRoutes: RouteRecordRaw[] = [
  {
    path: '/system',
    component: Layout,
    meta: {
      title: '系统管理',
      icon: 'guide',
    },
    children: [
      {
        path: 'user',
        component: () => import(/* webpackChunkName: "department-list" */'../views/system/user/index.vue'),
        meta: {
          title: '管理员列表',
          icon: 'list',
        },
      },
      // {
      //   path: 'role',
      //   component: () => import(/* webpackChunkName: "department-detail" */'../views/system/role/index.vue'),
      //   meta: {
      //     title: '角色管理',
      //     icon: 'documentation',
      //   },
      // },

    ],
  },
  // {
  //   path: '/product',
  //   component: Layout,
  //   meta: {
  //     title: '商品管理',
  //     icon: 'guide',
  //   },
  //   children: [
  //     {
  //       path: 'goods',
  //       component: () => import(/* webpackChunkName: "department-list" */'../views/product/goods/index.vue'),
  //       meta: {
  //         title: '商品列表',
  //         icon: 'list',
  //       },
  //     },
  //     {
  //       path: 'classes',
  //       component: () => import(/* webpackChunkName: "department-list" */'../views/product/classes/index.vue'),
  //       meta: {
  //         title: '分类列表',
  //         icon: 'list',
  //       },
  //     },

  //   ],
  // },
  // {
  //   path: '/order',
  //   component: Layout,
  //   meta: {
  //     title: '订单管理',
  //     icon: 'guide',
  //   },
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import(/* webpackChunkName: "department-detail" */'../views/order/index.vue'),
  //       meta: {
  //         title: '订单列表',
  //         icon: 'documentation',
  //       },
  //     },
  //   ],
  // },
  {
    path: '/canvas',
    component: Layout,
    meta: {
      title: 'canvas实践',
      icon: 'guide',
    },
    children: [
      {
        path: 'index',
        component: () => import(/* webpackChunkName: "draw-list" */'../views/canvas/index.vue'),
        meta: {
          title: 'draw',
          icon: 'list',
        },
      },
      {
        path: '/img',
        component: () => import(/* webpackChunkName: "draw-img" */'../views/canvas/draw.vue'),
        meta: {
          title: 'draw-img',
          icon: 'list',
        },
      },
    ],
  },
  {
    path: '/chat',
    component: Layout,
    meta: {
      title: '聊天',
      icon: 'guide',
    },
    children: [
      {
        path: 'index',
        component: () => import(/* webpackChunkName: "department-detail" */'../views/chat/index.vue'),
        meta: {
          title: '聊天室一',
          icon: 'documentation',
        },
      },
    ],
  },

]

const router = createRouter({
  routes: constantRoutes,
  history: createWebHistory(),
})

export default router
